app.controller('BusVehicleModelListCtrl', function($scope, ajax, $modal, toaster) {

    $scope.reload = $scope.page.loader('vehicle/bs/model/{pageIndex}/{pageSize}/page');
    $scope.$on('pageIndex', function(event, p) { $scope.reload(p, $scope.queryMap); });
    $scope.reload(1);
    
    var inserter = new Req.POST({ resource: $scope.resource });
    var deleter = new Req.DELETE({ resource: $scope.resource });
    
    // 新增、更新
    $scope.write = function(size, current_data, submit_type) {
        $scope.current_data = angular.copy(current_data);
        var modalInstance = $modal.open({
            templateUrl: 'template/bus/vehicle/addVehicleModel.html?v=79ca72ad04',
            controller: 'BusModalCtrl',
            size: size,
            resolve: {
                param: function() {
                    return {
                        "data": $scope.current_data,
                        "type": submit_type
                    };
                }
            }
        });

        modalInstance.result.then(function(param) {
            if (param.type == 'insert') {
                inserter.fields = param.data;
                inserter.resource = 'vehicle/bs/model/insert';
                $scope.page.add(inserter, $scope.reload);
            }
        });
    };

    //删除
    $scope.del = function(size, current_data, submit_type) {
		var modalInstance = $scope.delModal(size, current_data, submit_type);
        modalInstance.result.then(function(param) {
            if (param.type == 'delete') {
                deleter.id = param.data.id;
                deleter.resource = 'vehicle/bs/model/' + deleter.id + '/delete';
                $scope.page.del(deleter, $scope.reload);
            }
        });
    };

});
